# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Rémy Oudompheng <oudomphe@clipper.ens.fr>

pkgname=singular
_majver=4-3-2
_patchver=p10
_pkgver=${_majver}${_patchver}
pkgver=${_majver//-/.}${_patchver/p/.p}
pkgrel=1
pkgdesc='Computer Algebra System for polynomial computations'
arch=(loong64 x86_64)
url='https://www.singular.uni-kl.de/'
license=(GPL)
depends=(bash
         cddlib
         flint
         gcc-libs
         glibc
         gmp
         ntl
         readline)
provides=(singular-factory)
source=(ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/SOURCES/$_majver/singular-${_pkgver//-/.}.tar.gz)
sha256sums=('28c2c9fcfee954e00dfa56eb1a7d418d5b1de67c4398d25a0f2b8f73e71552a8')
options=(!zipman)

build() {
  cd singular-${_majver//-/.}

  # this uses malloc_usable_size, which is incompatible with fortification level 3
  export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/lib \
    --enable-bigintm-module \
    --enable-bigintm-module \
    --enable-Order-module \
    --enable-python-module \
    --enable-gfanlib-module \
    --enable-polymake-module
# https://bugzilla.gnome.org/show_bug.cgi?id=655517
  sed -e 's/ -shared / -Wl,-O1,--as-needed\0/g' -i libtool -i */libtool
  make
}

check() {
  cd singular-${_majver//-/.}

  # this uses malloc_usable_size, which is incompatible with fortification level 3
  export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

  make check
}
  
package() {
  cd singular-${_majver//-/.}
  make DESTDIR="$pkgdir" install
}
